package com.xiaoshuidi.cloud.module.system.api.user;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.system.api.user.dto.AdminUserRespDTO;
import com.xiaoshuidi.cloud.module.system.api.user.dto.CustomerUserRespDTO;
import com.xiaoshuidi.cloud.module.system.convert.user.UserConvert;
import com.xiaoshuidi.cloud.module.system.dal.dataobject.user.AdminUserDO;
import com.xiaoshuidi.cloud.module.system.dal.dataobject.user.CustomerUserDO;
import com.xiaoshuidi.cloud.module.system.dal.mysql.user.CustomerUserMapper;
import com.xiaoshuidi.cloud.module.system.service.user.AdminUserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.*;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;
import static com.xiaoshuidi.cloud.module.system.enums.ApiConstants.VERSION;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class CustomerUserApiImpl implements CustomerUserApi {

    @Resource
    private CustomerUserMapper customerUserMapper;

    @Override
    public CommonResult<Long> pushInformationToCenter(CustomerUserRespDTO customerUserRespDTO) {
        CustomerUserDO customerUserDO = customerUserMapper.selectByMobileAndOther(customerUserRespDTO);
        if (customerUserDO != null){
            return CommonResult.success(customerUserDO.getId());
        }
        CustomerUserDO customerUserDO1 = new CustomerUserDO()
                .setMobile(customerUserRespDTO.getMobile())
                .setUsername(customerUserRespDTO.getUsername())
                .setIdNumber(customerUserRespDTO.getIdNumber());
        customerUserMapper.insert(customerUserDO1);
        return CommonResult.success(customerUserDO1.getId());
    }
}
